<template>
  <div>
    <div class="card-goods" v-if="list.length>0">
      <div class="shop-name-left">
        <van-icon name="shop-o" size="18"/>
        <span>雾缘蒸汽</span>
      </div>
      <van-divider/>
      <div v-for="(item, i) in list" :key="i" class="card-item">
        <div class="card-goods-content">
          <van-checkbox v-model="item.checked" @click="checkChange(item)"/>
          <img
            @click="itemClick(item)"
            class="good-thumb"
            v-lazy="item.picUrl"
          />
          <div class="good-info">
            <div class="good-title" @click="itemClick(item)">
              <span>{{ item.goodsName }}</span>
            </div>
            <div class="good-type" @click="changeSku">
              <span>{{ item.specifications.join('') }}</span>
              <van-icon name="arrow-down"/>
            </div>
            <div class="good-counts">
              <span class="good-price">¥{{ item.price }}</span>

              <van-stepper v-if="item.isEdit" v-model="item.number" @change="coutChange(item,arguments)"
                           disableInput/>
              <div v-else>
                <span class="good-count" @click.stop="editCount(item,i)">x{{ item.number }}</span>
              </div>
            </div>

          </div>
        </div>
        <van-divider/>
      </div>
      <slot name="footer"></slot>
    </div>
    <van-empty v-else description="购物车是空的" :image="image"/>
  </div>
</template>

<script>
export default {
  name: 'CartItems',
  props: {
    list: Array,
    image: String
  },

  methods: {
    changeSku () {
      this.$emit('changeSku')
    },
    coutChange (item) {
      this.$emit('onItemCountChange', item)
    },
    itemClick (item) {
      this.$router.push({name: 'detail', params: {id: item.goodsId}})
    },
    editCount (item, index) {
      this.$set(this.list[index], 'isEdit', !item.isEdit)
    },
    checkChange (item, index) {
      this.$emit('onItemCheckChange', item)
    }
  }
}
</script>

<style scoped>
.card-item {
  margin: 0 5px 10px 5px;
  padding: 0;
}
.shop-name-left {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin: 10px 5px;
  font-weight: bold;
}

.card-goods-item {
  border-radius: 10px;
  box-shadow: 2px 3px 3px rgb(138, 138, 138);
  background-color: white;
  margin: 0 5px 10px 5px;
  padding: 5px;
  display: flex;
  flex-direction: row;
  align-items: center;

}

.ck-goods {
  margin: 5px;
}

.good-info {
  margin-left: 10px;
  flex-grow: 1;
  flex-direction: column;
  display: flex;
}

.good-counts {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  text-align: right;
}

.good-price {
  color: #db3d3c;
  font-weight: bold;
}

.good-title {
  color: black;
  font-size: 16px;
  font-weight: bold;
}

.good-type {
  background: #c5c5c5;
  margin: 7px 0;
  padding: 3px 5px;
  border-radius: 3px;
  width: max-content;
  color: gray;
  font-size: 10px;
}

.good-thumb {
  margin-left: 10px;
  width: 80px;
  height: 80px;
  border-radius: 10px;
}

.card-goods {
  display: block;
  background-color: white;
  margin: 10px 5px 5px 5px;
  padding: 5px;
  border-radius: 5px;
  box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);

}

.ck-goods {
  margin: 5px;
}

</style>
